//
//  ZGLOddsView.m
//  ZeegingLottery
//
//  Created by 蒂埃里 on 2018/4/14.
//  Copyright © 2018年 蒂埃里. All rights reserved.
//

#import "ZGLOddsView.h"

@interface ZGLOddsView ()


@end

@implementation ZGLOddsView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        [self setupUI];
    }
    
    return self;
}

- (UILabel *)typeLabel
{
    if (!_typeLabel) {
        _typeLabel = [[UILabel alloc]init];
        _typeLabel.textAlignment = 1;
        _typeLabel.numberOfLines = 0;
        _typeLabel.font = [UIFont systemFontOfSize:10];
        _typeLabel.textColor = [UIColor whiteColor];
        
    }
    
    return _typeLabel;
}

-(UIButton *)oddsButton
{
    if (!_oddsButton) {
        _oddsButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _oddsButton.titleLabel.font = [UIFont systemFontOfSize:labelFontSize];
        _oddsButton.backgroundColor = [UIColor whiteColor];
        [_oddsButton setTitleColor:sRGBHexAlpha(0xCCCCCC, 1.0) forState:UIControlStateNormal];
        [_oddsButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [_oddsButton setBackgroundImage:[UIImage imageNamed:@"btn_bg_normal"] forState:UIControlStateSelected];
        
    }
    
    return _oddsButton;
}

- (void)setupUI
{
    [self addSubview:self.typeLabel];
    [self addSubview:self.oddsButton];
    
    [_typeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self);
        make.top.equalTo(self);
        make.bottom.equalTo(self);
        make.right.equalTo(_oddsButton.mas_left);
    }];
    
    [_oddsButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self);
        make.right.equalTo(self);
        make.bottom.equalTo(self);
        make.left.equalTo(_typeLabel.mas_right);
        
    }];
    
    
    
}
- (void)initWithType:(oddsViewType )type
{
    
    switch (type) {
            
            //label & 按钮字竖排
        case oddsViewTypeLabelAndButtonVertical:{
            
            [self.typeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
                
                make.top.equalTo(self);
                make.left.equalTo(self);
                make.bottom.equalTo(self);
                make.width.mas_equalTo(15);
                
            }];
            
            [self.oddsButton mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(_typeLabel.mas_top);
                make.left.equalTo(_typeLabel.mas_right);
                make.bottom.equalTo(_typeLabel.mas_bottom);
                make.right.equalTo(self);
                
            }];
            
        }
            
            break;
            
            //label & 按钮字横排
        case oddsViewTypeLabelAndButtonHorizontall:{
            
            [self.typeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
                
                make.top.equalTo(self);
                make.left.equalTo(self);
                make.bottom.equalTo(self);
                make.width.mas_equalTo(15);
                
            }];
            
            [self.oddsButton mas_updateConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self);
                make.left.equalTo(_typeLabel.mas_right);
                make.bottom.equalTo(self);
                make.right.equalTo(self);
                
            }];
            
        }
            break;
            
            //按钮字竖排
        case  oddsViewTypeButtonVertical:{
            
            [self.typeLabel setHidden:YES];
            [self.oddsButton mas_updateConstraints:^(MASConstraintMaker *make) {
                
                make.top.equalTo(self);
                make.left.equalTo(self);
                make.bottom.equalTo(self);
                make.right.equalTo(self);
            }];
        }
            break;
            
            //按钮字横排
        case oddsViewTypeButtonHorizontall:{
            
            [self.typeLabel setHidden:YES];
            [self.oddsButton mas_updateConstraints:^(MASConstraintMaker *make) {
                
                make.top.equalTo(self);
                make.left.equalTo(self);
                make.bottom.equalTo(self);
                make.right.equalTo(self);
            }];
            
        }
            break;
            
        case oddsViewTypeButtonNoSale:{
            
            [self.oddsButton setHidden:YES];
            [self.typeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
                
                make.top.equalTo(self);
                make.left.equalTo(self);
                make.bottom.equalTo(self);
                make.width.mas_equalTo(15);
                
            }];
            
            UIButton *noSaleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [self addSubview:noSaleBtn];
            [noSaleBtn setTitle:@"未开售" forState:UIControlStateNormal];
            [noSaleBtn setTitleColor:RGBACOLOR(0xA0, 0xA0, 0xA0, 1.0) forState:UIControlStateNormal];
            noSaleBtn.titleLabel.font = [UIFont fontWithName:@"Arial" size:btnFontSize];
            noSaleBtn.layer.borderWidth = kBorderWidth;
            [noSaleBtn.layer setBorderColor:BorderColor.CGColor];
            [noSaleBtn setEnabled:NO];
            
            [noSaleBtn mas_updateConstraints:^(MASConstraintMaker *make) {

                make.top.equalTo(self);
                make.left.equalTo(_typeLabel.mas_right);
                make.right.equalTo(self);
                make.bottom.equalTo(self);
            }];
        }
            
        default:
            break;
    }
    
}


@end
